package com.cacho.s2b.lesson.vo;


import io.restassured.http.ContentType;
import io.restassured.http.Method;
import lombok.Getter;
import lombok.Setter;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description 接口请求需要的信息
 * @Author LingWei
 * @date 2023/12/31
 **/
@Getter
@Setter
public class RequestInfo {
    private Method method; // post, get
    private URL url;
    private String body;
    private ApiActivation activation;
    private ContentType contentType = ContentType.JSON; // application/json
    private Map<String,String> headers = new HashMap<>();
    private Map<String,Object> formDataMap = new HashMap<>();  // form data 类型的body

    // 空body时 post 请求
    public static RequestInfo postRequest(String url) throws MalformedURLException {
        RequestInfo req = new RequestInfo();
        req.setMethod(Method.POST);
        req.setContentType(ContentType.JSON);
        req.setBody("{}");
        req.setUrl(new URL(url));
        return req;
    }
    // 空body时 get 请求
    public static RequestInfo getRequest(String url) throws MalformedURLException{
        RequestInfo req = new RequestInfo();
        req.setMethod(Method.GET);
        req.setContentType(ContentType.TEXT); // text/plain 纯文本格式
        req.setUrl(new URL(url));
        return req;
    }
}
